home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
005
/
calyr2.arc
/
CALYR.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1985-09-17
|
7KB
|
257 lines
Program calyr;
{ *********** PUBLIC DOMAIN ************
Accepts year as input...
Year should be between 1901 and 2099 inclusive;
Accepts 2 digit year, if 2 digit assumes 19xx;
Displays 1st 6 months, then second 6 months, allows return to 1st 6;
If valid year not entered on command line, ask for year.
If letter 'P' in command line, display calendar on printer,
If letter 'S' in command line, display calendar on screen,
If neither 'P' nor 'S' in command line, ask where to display.
MODIFICATION HISTORY
DATE AUTHOR CHANGES
04/28/85 William Chestnut Original Version
5800 Sunset Blvd.
LA, CA 90078
09/15/85 Roy J. Collins 1. Allow display of calendar on screen or printer
P.O.B. 1192 2. Re-structured parts of code.
Leesburg,VA 22075
}
Const
day_letters = ' S M T W T F S';
Type
parmtype = String[127];
Str = String[80];
Var
year,dow : Integer; { Year is target year for calendar, Dow is the day }
{ number of 1/1/xxxx, Sunday=1, Monday=2, etc. }
cal : Array[1..12,1..42] Of Integer;
dpm : Array[1..12] Of Integer; { number of days in each month }
m : Integer;
ch : Char;
yearstr : parmtype;
out_flag : Char;
Procedure getparm(Var s:parmtype); { Get command line parameter }
Var
parms : parmtype Absolute CSeg:$80;
p : Integer;
Begin
s:='';
out_flag := ' ';
If Pos('S',parms) > 0 Then Begin
out_flag := 'S';
Delete(parms,Pos('S',parms),1);
End
Else
If Pos('s',parms) > 0 Then Begin
out_flag := 'S';
Delete(parms,Pos('s',parms),1);
End
Else
If Pos('P',parms) > 0 Then Begin
out_flag := 'P';
Delete(parms,Pos('P',parms),1);
End
Else
If Pos('p',parms) > 0 Then Begin
out_flag := 'P';
Delete(parms,Pos('p',parms),1);
End;
While (parms <> '') And (parms[1]=' ') Do
Delete(parms,1,1);
While ((parms <> '') And (parms[Length(parms)]=' ')) Do
Delete(parms,Length(parms),1);
s := parms;
End;
Procedure getyear; { Gets Year from keyboard, Calculates Dow }
Var
dayofweek : Real;
errorcode : Integer;
Begin { GetYear }
year :=0;
While year = 0 Do Begin
getparm(yearstr);
If Length(yearstr) = 0 Then Begin
Write('YEAR ');
ReadLn(yearstr);
End;
Val(yearstr,year,errorcode);
If errorcode <> 0 Then
year := 0;
End;
If ( year > 0 ) And ( year <= 99 ) Then
year := year + 1900;
While ( year < 1901 ) Or ( year > 2099 ) Do Begin
Writeln('Year must be between 1901 and 2099');
getyear;
End;
dayofweek:=Int((year-1901)*365.25);
While dayofweek > 28000 Do
dayofweek := dayofweek - 28000;
dow := Round(dayofweek) Mod 7 + 3;
If dow > 7 Then
dow := dow - 7;
End; { GetYear }
Procedure fillinarray;
Var
m,d,date : Integer ;
Begin
For m := 1 To 12 Do { sets days per month to DPM[ ] }
Case m Of
1,3,5,7,8,10,12 : dpm[m] := 31;
4,6,9,11 : dpm[m] := 30;
2 : dpm[m] := 28;
End; (* case *)
If year Mod 4 = 0 Then { end set days per month to DPM[ ] }
dpm[2] := 29;
For m := 1 To 12 Do { set Cal [ , ] to 0 }
For d := 1 To 42 Do cal[m,d] := 0;
For m := 1 To 12 Do Begin
For date := 1 To dpm[m] Do
cal[m,dow+date-1] := date;
dow := dow + dpm[m];
While dow > 7 Do
dow := dow - 7;
End;
End; { FillInArray }
Procedure displayamonth;
Var
i,j,k : Integer;
Begin
Writeln(day_letters);
For k := 0 To 5 Do Begin
For j := 1 To 7 Do
If cal[m,k*7+j] <> 0 Then
Write(cal[m,k*7+j]:3) Else Write(' ');
Writeln;
End;
Writeln;
Writeln;
End;
Function month_name(month:Integer):Str;
Begin
Case month Of
1 : month_name := 'January';
2 : month_name := 'February';
3 : month_name := 'March';
4 : month_name := 'April';
5 : month_name := 'May';
6 : month_name := 'June';
7 : month_name := 'July';
8 : month_name := 'August';
9 : month_name := 'September';
10 : month_name := 'October';
11 : month_name := 'November';
12 : month_name := 'December';
End;
End; (* func month_name *)
Procedure print_a_week(month,week:Integer);
Var
s : Str;
i,j,k : Integer;
Begin
If week < 0 Then Begin
For i := month To month + 2 Do Begin
s := month_name(i);
Write(Lst,s,' ':26-Length(s));
End;
Writeln(Lst);
For i := 1 To 3 Do
Write(Lst,day_letters,' ');
End
Else Begin
For j := 1 To 7 Do
If cal[month,week*7+j] <> 0 Then
Write(Lst,cal[month,week*7+j]:3)
Else
Write(Lst,' ');
Write(Lst,' ');
End;
End; (* proc print_a_week *)
Procedure print_calendar;
Var
w : Integer;
Begin
Writeln(Lst);
Writeln(Lst,' ',year);
Writeln(Lst);
m := 1;
While m < 12 Do Begin
print_a_week(m,-1);
Writeln(Lst);
For w := 0 To 5 Do Begin
print_a_week(m,w);
print_a_week(m+1,w);
print_a_week(m+2,w);
Writeln(Lst);
End;
Writeln(Lst);
Writeln(Lst);
m := m + 3;
End;
End; (* proc print_calendar *)
Procedure disphalf(start:Integer);
Var
y : Integer;
Begin
y := 3;
For m := start To start+2 Do Begin
Window((m-start)*25+1,y,(m-(start-1))*25-1,y+10);
Writeln;
Writeln(month_name(m));
displayamonth;
End;
start := start+3;
y := 13;
For m := start To start+2 Do Begin
Window((m-start)*25+1,y,(m-(start-1))*25-1,y+10);
Writeln;
Writeln;
Writeln;
Writeln(month_name(m));
displayamonth;
End;
Window(1,1,80,25);
End;
Begin {main body}
getyear;
fillinarray;
If ((out_flag <> 'S') And (out_flag <> 'P')) Then Begin
Write('Display calendar on S)creen or P)rinter? (S/P) ');
Repeat
Read(Kbd,out_flag);
out_flag := UpCase(out_flag);
Until ((out_flag='S') Or (out_flag='P'));
Writeln(out_flag);
End;
If out_flag = 'P' Then
print_calendar
Else
Repeat
ClrScr;
Writeln('YEAR ',year);
disphalf(1);
Writeln;
Write('Type any key for second half ');
Read(Kbd,ch);
ClrScr;
Writeln('YEAR ',year);
disphalf(7);
Writeln;
Write('Enter a 1 to see the first half again, any other key to quit ');
Read(Kbd,ch);
Until ch <> '1';
End.